﻿using System.Collections.Generic;

namespace WebApmDemo1.Models
{

    /// <summary>
    /// Skywalking告警数据模型
    /// </summary>
    public class AlarmMsg
    {
        /// <summary>
        /// 范围。所有范围都在
        /// <see cref="org.apache.skywalking.oap.server.core.source.DefaultScopeDefine"/>
        /// </summary>
        public int scopeId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string? scope { get; set; }
        /// <summary>
        /// 目标范围实体名称
        /// </summary>
        public string? name { get; set; }
        /// <summary>
        /// 与名称匹配的作用域实体的 ID。使用关系范围时，它是源实体 ID。
        /// </summary>
        public string? id0 { get; set; }
        /// <summary>
        /// 使用关系范围时，它是目标实体 ID。否则，它是空的
        /// </summary>
        public string? id1 { get; set; }
        /// <summary>
        /// 中配置的规则名称,详情查看alarm-settings.yml配置
        /// </summary>
        public string? ruleName { get; set; }
        /// <summary>
        /// 报警消息
        /// </summary>
        public string? alarmMessage { get; set; }
        /// <summary>
        /// 开始时间
        /// </summary>
        public long? startTime { get; set; }
        /// <summary>
        /// 标签 配置的标签alarm-settings.yml
        /// </summary>
        public List<tag>? tags { get; set; }


        public class tag
        {
            public string? key { get; set; }
            public string? value { get; set; }
        }



        public string SendMsg()
        {
            var sendMsg = string.Empty;
            if (scopeId > 0)
                sendMsg += $"scopeId:{scopeId} \n";
            if (scope != null)
                sendMsg += $"scope:{scope} \n";
            if (name != null)
                sendMsg += $"name:{name} \n";
            if (id0 != null)
                sendMsg += $"id0:{id0}  \n";
            if (ruleName != null)
                sendMsg += $"ruleName:{ruleName}  \n";
            if (alarmMessage != null)
                sendMsg += $"alarmMessage:{alarmMessage} \n";
            if (startTime != null)
                sendMsg += $"startTime:{startTime} \n";
            return sendMsg;
        }

        /// <summary>
        /// 忽略接口
        /// </summary>
        /// <returns></returns>
        public static HashSet<string> IgnoreInterface()
        {
            var result = new HashSet<string>();
            //用户二维码登录
            result.Add("api/Passport/CheckErCodeLoginStatus");
            //长链接
            result.Add("api/msgHub");
            //请求外部接口 http://vendorotthapi.mogul-tech.com/VendorApi/QueryAndSaveData 超时
            result.Add("/api/Order/Quote/Query");
            //请求外部接口 http://vendorotthapi.mogul-tech.com/VendorApi/QueryAndSaveData 超时
            result.Add("/api/ICVIP_Material_Api_Svc_VendorQuote_IVendorQuoteService/Query");
            //请求外部接口 http://vendorotthapi.mogul-tech.com/Scrapyrt/GetCrawlQuotedRankData 超时
            result.Add("/api/Order/RfqItemQuoteOptimize/GetPNComparePriceScheduleUpdateTime");
            //请求外部接口 http://vendorotthapi.mogul-tech.com/Scrapyrt/GetCrawlQuotedRankData 超时
            result.Add("/api/ICVIP_CRM_Business_Api_Order_IRfqItemQuoteOptimizeService/GetPNComparePriceScheduleUpdateTime");
            return result;
        }
    }

}
